package com.paas.form.core.element.base;

import com.gencode.util.CodeBuildNew;
import com.paas.common.util.BeanUtil;
import com.paas.common.util.StringUtil;
import com.paas.form.core.element.field.FieLdsModel;
import com.paas.form.core.element.jsContent.ScriptContent;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;

public class Utilmethod {



    //添加属性绑定
    public static String attriAdd(FieLdsModel field){
        if(BeanUtil.isEmpty(field)){
            return "";
        }
        StringBuffer attrsStr = new StringBuffer();
        if(field.getPlaceholder() != null && field.getPlaceholder() != ""){
            String attrItem= " placeholder=\"" +field.getPlaceholder() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getSpan() != null && field.getSpan() != 0){
            String attrItem= " :span=\"" +field.getSpan() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getShowLevel() != null && field.getShowLevel() != ""){
            String attrItem= " showLevel=\"" +field.getShowLevel() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getSearchMultiple() != null && field.getSearchMultiple() != ""){
            String attrItem= " searchMultiple=\"" +field.getSearchMultiple() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getSearchType() != null && field.getSearchType() != 0){
            String attrItem= " :searchType=\"" +field.getSearchType() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getAddressParams() != null ){
            String attrItem= " :addressParams=\"" +field.getAddressParams() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getFileSize() != null && field.getFileSize() != 0){
            String attrItem= " :fileSize=\"" +field.getFileSize() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getShowalllevels() != null ){
            String attrItem= " :showalllevels=\"" +field.getShowalllevels() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getStepstrictly() != null ){
            String attrItem= " :stepstrictly=\"" +field.getStepstrictly() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getContent() != null && field.getContent() != ""){
            String attrItem= " content=\"" +field.getContent() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getHref() != null && field.getHref() != ""){
            String attrItem= " href=\"" +field.getHref() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getTarget() != null && field.getTarget() != ""){
            String attrItem= " target=\"" +field.getTarget() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getAlign() != null && field.getAlign() != ""){
            String attrItem= " align=\"" +field.getAlign() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getTitle() != null && field.getTitle() != ""){
            String attrItem= " title=\"" +field.getTitle() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getInterfaceId() != null && field.getInterfaceId() != ""){
            String attrItem= " interfaceId=\"" +field.getInterfaceId() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getInterfaceName() != null && field.getInterfaceName() != ""){
            String attrItem= " interfaceName=\"" +field.getInterfaceName() + "\" ";
            attrsStr.append(attrItem);
        }
//        if(field.getColumnOptions() != null && field.getColumnOptions() != ""){
//            String attrItem= " columnOptions=\"" +field.getColumnOptions() + "\" ";
//            attrsStr.append(attrItem);
//        }
        if(field.getPropsValue() != null && field.getPropsValue() != ""){
            String attrItem= " propsValue=\"" +field.getPropsValue() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getPopupType() != null && field.getPopupType() != ""){
            String attrItem= " popupType=\"" +field.getPopupType() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getPopupTitle() != null && field.getPopupTitle() != ""){
            String attrItem= " popupTitle=\"" +field.getPopupTitle() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getPopupWidth() != null && field.getPopupWidth() != ""){
            String attrItem= " popupWidth=\"" +field.getPopupWidth() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getPageSize() != null && field.getPageSize() != 0){
            String attrItem= " :pageSize=\"" +field.getPageSize() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getHasPage() != null ){
            String attrItem= " :hasPage=\"" +field.getHasPage() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getTemplateJson() != null && field.getTemplateJson() != ""){
            String attrItem= " :templateJson=\"" +field.getTemplateJson() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getTabposition() != null && field.getTabposition() != ""){
            String attrItem= " tabposition=\"" +field.getTabposition() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getJustify() != null && field.getJustify() != ""){
            String attrItem= " justify=\"" +field.getJustify() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getHeader() != null && field.getHeader() != ""){
            String attrItem= " header=\"" +field.getHeader() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getAlways() != null && field.getAlways() != ""){
            String attrItem= " always=\"" +field.getAlways() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getAccordion() != null ){
            String attrItem= " :accordion=\"" +field.getAccordion() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getClosable() != null ){
            String attrItem= " :closable=\"" +field.getClosable() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getShowicon() != null ){
            String attrItem= " :showicon=\"" +field.getShowicon() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getDatasetType() != null && field.getDatasetType() != "" ){
            String attrItem= " datasetType=\"" +field.getDatasetType() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getField() != null && field.getField() != "" ){
            String attrItem= " field=\"" +field.getField() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getValue() != null && field.getValue() != ""){
            String attrItem= " value=\"" +field.getValue() + "\" ";
            attrsStr.append(attrItem);
        }

        if(field.getMaxlength() != null && field.getMaxlength() != 0){
            String attrItem= " :maxlength=\"" +field.getMaxlength() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getReadonly() != null && field.getReadonly().equals(true)){
            String attrItem= " readonly ";
            attrsStr.append(attrItem);
        }
        if(field.getDisabled() != null && field.getDisabled().equals(true)){
            String attrItem= " :disabled=\"" +field.getDisabled() + "\" ";
            attrsStr.append(attrItem);
        }else{
            String attrItem= " :disabled=\"isdetail\" ";
            attrsStr.append(attrItem);
        }
        if(field.getClearable() != null && field.getClearable().equals(true)){
            String attrItem= " clearable ";
            attrsStr.append(attrItem);
        }
        if(field.getPrefixicon() != null && field.getPrefixicon() != ""){
            String attrItem= " prefix-icon=\"" +field.getPrefixicon() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getSuffixicon() != null && field.getSuffixicon() != ""){
            String attrItem= " suffix-icon=\"" +field.getSuffixicon() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getStyle() != null && field.getStyle() != ""){
            String attrItem= "style ='" +field.getStyle().toString().replaceAll("[{]","").replaceAll("}","").replaceAll("\"","") + "' ";
            attrsStr.append(attrItem);
        }
//        if(field.getShowwordlimit() != null && field.getShowwordlimit().equals(true)){
//            String attrItem= " true ";
//            attrsStr.append(attrItem);
//        }
        if(field.getSize() != null && field.getSize() != ""){
            String attrItem= " size=\"" +field.getSize() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getMin() != null ){
            String attrItem= " :min=\"" +field.getMin() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getMax() != null && field.getMax() != 0){
            String attrItem= " :max=\"" +field.getMax() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getType() != null && field.getType() != ""){
            String attrItem= " type=\"" +field.getType() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getAutosize() != null && field.getAutosize() != ""){
            String attrItem= " :autosize=\"" +field.getAutosize().replaceAll("\"","") + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getStep() != null && field.getStep() != 0){
            String attrItem= " :step=\"" +field.getStep() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getPrecision() != null && field.getPrecision() != 0){
            String attrItem= " :precision=\"" +field.getPrecision() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getTextStyle() != null && field.getTextStyle() != ""){
            String attrItem= " textStyle=\"" +field.getTextStyle() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getLineHeight() != null && field.getLineHeight() != 0){
            String attrItem= " :lineHeight=\"" +field.getLineHeight() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getFontSize() != null && field.getFontSize() != 0){
            String attrItem= " :fontSize=\"" +field.getFontSize() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getControlsposition() != null && field.getControlsposition() != ""){
            String attrItem= " controls-position=\"" +field.getControlsposition() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getShowChinese() != null && field.getShowChinese() != false){
            String attrItem= " :showChinese=\"" +field.getShowChinese() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getShowpassword() != null && field.getShowpassword() != false){
            String attrItem= " show-password " ;
            attrsStr.append(attrItem);
        }
        if(field.getFilterable() != null && field.getFilterable().equals(true)){
            String attrItem= " filterable " ;
            attrsStr.append(attrItem);
        }
        if(field.getMultiple() != null && field.getMultiple().equals(true)){
            String attrItem= " :multiple=\"" +field.getMultiple() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getSeparator() != null && field.getSeparator() != ""){
            String attrItem= " separator=\"" +field.getSeparator() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getIsRange() != null && field.getIsRange().equals(true)){
            String attrItem= " is-range " ;
            attrsStr.append(attrItem);
        }
        if(field.getRangeSeparator() != null &&field.getRangeSeparator() != ""){
            String attrItem= " range-separator=\"" +field.getRangeSeparator() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getStartPlaceholder() != null && field.getStartPlaceholder() != ""){
            String attrItem= " start-placeholder=\"" +field.getStartPlaceholder() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getEndPlaceholder() != null && field.getEndPlaceholder() != ""){
            String attrItem= " end-placeholder=\"" +field.getEndPlaceholder() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getFormat() != null && field.getFormat() != ""){
            String attrItem= " format=\"" +field.getFormat() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getColorformat() != null && field.getColorformat() != ""){
            String attrItem= " color-format=\"" +field.getColorformat() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getValueformat() != null && field.getValueformat() != ""){
            String attrItem= " value-format=\"" +field.getValueformat() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getActiveTxt() != null && field.getActiveTxt() != ""){
            String attrItem= " active-text=\"" +field.getActiveTxt() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getInactiveTxt() != null && field.getInactiveTxt() != ""){
            String attrItem= " inactive-text=\"" +field.getInactiveTxt() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getActivecolor() != null && field.getActivecolor() != ""){
            String attrItem= " active-color=\"" +field.getActivecolor() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getInactivecolor() != null && field.getInactivecolor() != ""){
            String attrItem= " inactive-color=\"" +field.getInactivecolor() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getActivevalue() != null && field.getActivevalue() != 0){
            String attrItem= " :active-value=\"" +field.getActivevalue() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getInactivevalue() != null ){
            String attrItem= " :inactive-value=\"" +field.getInactivevalue() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getPickeroptions() != null && field.getPickeroptions() != ""){
            String attrItem= " picker-options='" +field.getPickeroptions().replaceAll("[{]","").replaceAll("}","").replaceAll("\"","") + "' ";
            attrsStr.append(attrItem);
        }
        if(field.getShowscore() != null && field.getShowscore().equals(true)){
            String attrItem= " show-score " ;
            attrsStr.append(attrItem);
        }
        if(field.getShowtext() != null && field.getShowtext().equals(true)){
            String attrItem= " show-text " ;
            attrsStr.append(attrItem);
        }
        if(field.getAllowhalf() != null && field.getAllowhalf().equals(true)){
            String attrItem= " allow-half " ;
            attrsStr.append(attrItem);
        }
        if(field.getShowalpha() != null && field.getShowalpha().equals(true)){
            String attrItem= " show-alpha " ;
            attrsStr.append(attrItem);
        }
        if(field.getShowstops() != null && field.getShowstops().equals(true)){
            String attrItem= " show-stops " ;
            attrsStr.append(attrItem);
        }
        if(field.getRange() != null && field.getRange().equals(true)){
            String attrItem= " range " ;
            attrsStr.append(attrItem);
        }
        if(field.getShowTip() != null && field.getShowTip().equals(true)){
            String attrItem= " :showTip=\"" +field.getShowTip() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getAccept() != null && field.getAccept() != ""){
            String attrItem= " accept=\"" +field.getAccept() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getSizeUnit() != null && field.getSizeUnit() != ""){
            String attrItem= " sizeUnit=\"" +field.getSizeUnit() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getLimit() != null && field.getLimit() != 0){
            String attrItem= " :limit=\"" +field.getLimit() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getButtonText() != null && field.getButtonText() != ""){
            String attrItem= " buttonText=\"" +field.getButtonText() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getContentposition() != null && field.getContentposition() != ""){
            String attrItem= " content-position=\"" +field.getContentposition() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getRelationId() != null && field.getRelationId() != ""){
            String attrItem= " relationId=\"" +field.getRelationId() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getLevel() != null && field.getLevel() != 0){
            String attrItem= " :level=\"" +field.getLevel() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getRelationField() != null && field.getRelationField() != "" ){
            String attrItem= " relationField=\"" +field.getRelationField() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getShowField() != null && field.getShowField() != ""){
            String attrItem= " showField=\"" +field.getShowField() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getConfig().getIsStorage() != null && field.getConfig().getIsStorage() != ""){
            String attrItem= " isStorage=\"" +field.getConfig().getIsStorage() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getSelectType() != null && field.getSelectType() != ""){
            String attrItem= " selectType=\"" +field.getSelectType() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getActiveNames() != null && field.getActiveNames() != ""){
            String attrItem= " activeNames=\"" +field.getActiveNames() + "\" ";
            attrsStr.append(attrItem);
        }
        if(field.getSelectType() != null &&field.getSelectType().equals("custom")){
            if(field.getAbleDepIds() != null &&field.getAbleDepIds() != ""){
                String attrItem= " :ableDepIds=\"" +field.getAbleDepIds().replaceAll("\"","'") + "\" ";
                attrsStr.append(attrItem);
            }
            if(field.getAblePosIds() != null &&field.getAblePosIds() != ""){
                String attrItem= " :ablePosIds=\"" +field.getAblePosIds().replaceAll("\"","'") + "\" ";
                attrsStr.append(attrItem);
            }
            if(field.getAbleUserIds() != null &&field.getAbleUserIds() != ""){
                String attrItem= " :ableUserIds=\"" +field.getAbleUserIds().replaceAll("\"","'") + "\" ";
                attrsStr.append(attrItem);
            }
            if(field.getAbleRoleIds() != null && field.getAbleRoleIds() != ""){
                String attrItem= " :ableRoleIds=\"" +field.getAbleRoleIds().replaceAll("\"","'") + "\" ";
                attrsStr.append(attrItem);
            }
            if(field.getAbleGroupIds() != null &&field.getAbleGroupIds() != ""){
                String attrItem= " :ableGroupIds=\"" +field.getAbleGroupIds().replaceAll("\"","'") + "\" ";
                attrsStr.append(attrItem);
            }
            if(field.getAbleIds() != null && field.getAbleIds() != "" ){
                String attrItem= " :ableIds=\"" +field.getAbleIds().replaceAll("\"","'") + "\" ";
                attrsStr.append(attrItem);
            }
        }else if(field.getSelectType() != null &&(field.getSelectType().equals("dep") || field.getSelectType().equals("pos") || field.getSelectType().equals("role") || field.getSelectType().equals("group"))){
            if(field.getRelationFieId() != null && field.getRelationFieId() != ""){
                String attrItem= " ableRelationIds=\" Array.isArray(dataForm." +field.getRelationFieId() + ") ? dataForm." +field.getRelationFieId() + "  [dataForm." +field.getRelationFieId() +"]\"";
                attrsStr.append(attrItem);
            }
        }



        return attrsStr.toString();

    }



    //js个部分拼接方法
    public static ScriptContent scriptContentAdd(ScriptContent mainScriptContent ,ScriptContent itemScript){
        if(BeanUtil.isEmpty(mainScriptContent)){
            mainScriptContent = new ScriptContent();
        }
        if(BeanUtil.isNotEmpty(itemScript)){
            //把个item模块的js/data/methods 拼接
            if(StringUtil.isNotEmpty(itemScript.getComponents())){
                String newComStr = itemScript.getComponents();
                if(StringUtil.isNotEmpty(mainScriptContent.getComponents())){
                    mainScriptContent.setComponents(mainScriptContent.getComponents() + "\n" +newComStr);
                }else {
                    mainScriptContent.setComponents(newComStr);
                }
            }
            if(StringUtil.isNotEmpty(itemScript.getData())){
                String newDataStr = itemScript.getData();
                if(StringUtil.isNotEmpty(mainScriptContent.getData())){
                    mainScriptContent.setData(mainScriptContent.getData() + "\n" +newDataStr);
                }else {
                    mainScriptContent.setData(newDataStr);
                }
            }
            if(StringUtil.isNotEmpty(itemScript.getMethods())){
                String newMethodsStr = itemScript.getMethods();
                if(StringUtil.isNotEmpty(mainScriptContent.getMethods())){
                    mainScriptContent.setMethods(mainScriptContent.getMethods() + "\n" + newMethodsStr);
                }else {
                    mainScriptContent.setMethods(newMethodsStr);
                }
            }
            if(StringUtil.isNotEmpty(itemScript.getProps())){
                String newPropsStr = itemScript.getProps();
                if(StringUtil.isNotEmpty(mainScriptContent.getProps())){
                    mainScriptContent.setProps(mainScriptContent.getProps() + "\n" + newPropsStr);
                }else {
                    mainScriptContent.setProps(newPropsStr);
                }
            }
        }
        return mainScriptContent;
    }

}
